package object5.library;

public class Book {
    //书名
    private String name;//让使用者通过getter/setter来使用,而不是直接访问属性来使用
    //好处:例如后续要修改价格,成本价是定价的8折,那么只需在getter中修改即可,让返回的price乘以0.8
    //作者
    private String author;
    //价格
    private double price;
    //类型
    private String type;
    //是否借出
    private boolean isBorrowed;

    public Book(String name,String author,double price,String type){
        this.name = name;
        this.author = author;
        this.price = price;
        this.type = type;
        this.isBorrowed = false;//新书默认没有借出去
    }

    //生成getter/setter方法

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    //对于boolean类型,自动生成的名字风格与其他的不一样
    public boolean isBorrowed() {
        return isBorrowed;
    }

    public void setBorrowed(boolean borrowed) {
        isBorrowed = borrowed;
    }
    @Override
    public String toString(){
        return "[" + name + ',' + author + ',' + price + ',' + type + ',' + (isBorrowed ? "已借出":"未借出") + "]";
    }
}
